<extend name="Common@Layout:hui-admin" />
<block name="title"><title>编辑角色</title></block>
<block name="style">
<style>
.sortinput {width: 40px;margin-right:10px;}
</style>
</block>

<block name="main">
<div class="pd-20">
	<form action="{:U('Authgroupadmin/edit_post')}" method="post" class="form form-horizontal validator_form close-dialog">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-6">
				<input type="text" class="input-text" name="title" value="{$info.title}" placeholder=""  data-rule="角色名称:required;remote[/users/Authgroupadmin/checkauth/id/{$info.id|default=0}]">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>角色描述：</label>
			<div class="formControls col-6">
				<textarea class="input-text" name="desc" style="height:60px;" data-rule="角色描述:required;">{$info.desc}</textarea>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>状态：</label>
			<div class="formControls col-6">
				<php>if(!isset($info['status'])) $info['status'] = 1;</php>
				<div class="radio-box">
				    <label><input type="radio" name="status" value="1" <eq name="info['status']" value="1">checked</eq>> 启用</label>
				</div>
				<div class="radio-box">
				    <label><input type="radio" name="status" value="0" <eq name="info['status']" value="0">checked</eq>> 禁用</label>
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">网站角色：</label>
			<div class="formControls col-10">
				<php>
					$groups = C('AUTH_MINI_ROLE_GROUP');
					$curgroup = $groups[$_SESSION['auth_role_group']];
					$tree = $tree = new \Think\Tree();
					$m = M('AuthRule');
					
					$tmp = explode(',',$info['rules']);
					foreach($tmp as $r){
						$rules[$r] = $r;
					}
					
				</php>
				<table class="table" id="treetable">
					<volist name="curgroup" id="vo">
						<tr>
							<th scope="col" colspan="2">{$vo}</th>
						</tr>
						<php>
							$map['group'] = $vo;
							$datas = $m->where($map)->order('listorder desc')->select();
							$tree->init($datas);
							$treedata = $tree->get_tree_array(0, $str);
						</php>
						<volist name="treedata" id="tt">
						<php>print_table($tt,0,$rules);</php>
						</volist>
					</volist>
				</table>
				<php>function print_table($data,$level,$rules){</php>
				<tr id="node-{$data.id}" <if condition="$data.parentid neq 0">class="child-of-node-{$data.parentid}"</if>>
		            <td><span style="margin-left:{$level*20}px"></span>└─ <label><input type="checkbox" value="{$data.id}" name="rule[]" <php> if($rules[$data['id']]) echo 'checked';</php>>{$data.title|default='未设置'}</label></td>
		        </tr>
		        <php>
		        	if($data['child']){
		        		//执行递归
		        		foreach($data['child'] as $t){
		        			print_table($t,$level+1,$rules);
		        		}
		        	}
		        </php>
				<php>}</php>
			</div>
		</div>
		<if condition="$_SESSION['auth_role_group'] neq 'teacher'">
		<div class="row cl">
			<label class="form-label col-2">校区：</label>
			<div class="formControls col-10">
				<php>
					$xqdata = F('Xiaoqu/xiaoqu');
					$xq = explode(',',$info['xiaoqu']);
					foreach($xq as $q){
						$xiaoqu[$q] = $q;
					}
				</php>
				<volist name="xqdata" id="xqd">
				<label><input type="checkbox" value="{$xqd.id}" <php> if($xiaoqu[$xqd['id']]) echo 'checked';</php>  name="xiaoqu[]">{$xqd.title}</label><br/>
				</volist>
			</div>
		</div>
		</if>
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<input type="hidden" name="id" value="{$info.id}">
				<input type="hidden" name="group" value="{$_SESSION['auth_role_group']}">
				<button type="submit" style="width:200px;" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</div>
</block>

<block name="script">
<script>

$("#treetable").treeTable({expandable:true,clickableNodeNames:false,childPrefix:'child-of-',treeColumn:0});//treeColumn：0表示表格第二列显示树形结构。但是会影响此表单之后的树形表单显示
</script>
</block>